package com.ymk.utlis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class WxPayUtil {

    private final static Logger logger = LoggerFactory.getLogger(WxPayUtil.class);

    public static String readData(HttpServletRequest request) {
        StringBuffer sb = new StringBuffer();

        try (ServletInputStream inputStream = request.getInputStream();
             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        ) {
            String line;

            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }

        } catch (IOException e) {
            logger.error("读取数据流异常:{}", e);
        }

        return sb.toString();
    }
}